home *** CD-ROM | disk | FTP | other *** search
/ ASME's Mechanical Engine…ing Toolkit 1997 December / ASME's Mechanical Engineering Toolkit 1997 December.iso / c_lang / tc-pull.lzh / TC_BIOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-26  |  16.8 KB  |  448 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3.  
  4. union REGS inreg,outreg;
  5.  
  6.  
  7.  
  8.  
  9. /*  ╔══  FUNCTION DECLARATIONS ═══════════════════════╗  */
  10.  
  11. void biosbox(int, int, int, int, int, int);
  12. void ccls(int);
  13. void cls(void);
  14. void cursor(int);
  15. void gotoxy(int, int);
  16. void put_ca(char, int, int);
  17. void put_cai(char, int);
  18. void put_str(char *, int);
  19. int scroll(int, int, int, int, int, int);
  20. void smode(int);
  21. int vmode(void);
  22. char what_xy(int, int);
  23. int where_x(void);
  24. int where_y(void);
  25.  
  26. /*  ╚══  FUNCTION DECLARATIONS ═══════════════════════╝  */
  27.  
  28.  
  29. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  30. /*  ║ Function :  biosbox(upCOL,upROW,lowCOL,lowROW,attr,type);            ║  */
  31. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  32. /*  ║ draws box and clears center to a specified attribute (w/bios  calls) ║  */
  33. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  34. /*  ║ Usage    : biosbox(upCOL,upROW,lowCOL,lowROW,attr,type);             ║  */
  35. /*  ║                                                                      ║  */
  36. /*  ║ Returns  : nothing                                                   ║  */
  37. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  38. void biosbox(upCOL,upROW,lowCOL,lowROW,attr,type)
  39. int upCOL,upROW,lowCOL,lowROW,attr,type;
  40. {
  41.      register int x;
  42.      int wide;
  43.      char UL,UR,LL,LR,SD,TB;
  44.      
  45.      switch(type)  {
  46.           case 1 :    /* single line box     */
  47.           UL =  218;
  48.           UR =  191;
  49.           LL =  192;
  50.           LR =  217;
  51.           SD =  179;
  52.           TB = 196;
  53.           break;
  54.           
  55.           case 2 :    /* double line box     */
  56.           UL =  201;
  57.           UR =  187;
  58.           LL =  200;
  59.           LR =  188;
  60.           SD =  186;
  61.           TB = 205;
  62.           break;
  63.           
  64.           case 3 :    /* double sides - single top  */
  65.           UL =  214;
  66.           UR =  183;
  67.           LL =  211;
  68.           LR =  189;
  69.           SD =  186;
  70.           TB =  196;
  71.           break;
  72.           
  73.           case 4 :
  74.           UL =  213;  /* single sides - double top  */
  75.           UR =  184;
  76.           LL =  212;
  77.           LR =  190;
  78.           SD =  179;
  79.           TB =  205;
  80.           break;
  81.           
  82.           case 5 :
  83.           UL =  219;  /* bold box  */
  84.           UR =  219;
  85.           LL =  219;
  86.           LR =  219;
  87.           SD =  219;
  88.           TB =  219;
  89.           break;
  90.           
  91.           default:
  92.           UL =  218;
  93.           UR =  191;
  94.           LL =  192;
  95.           LR =  217;
  96.           SD =  179;
  97.           TB = 196;
  98.      }
  99.      wide = (lowCOL + 1 ) - upCOL;
  100.      
  101.      for(x = upROW;x <= lowROW;x++)  {
  102.           gotoxy(upCOL,x);
  103.           put_ca(' ',attr,wide);
  104.      }
  105.      
  106.      gotoxy(upCOL,upROW);
  107.      put_ca(TB,attr,wide);
  108.      gotoxy(upCOL,lowROW);
  109.      put_ca(TB,attr,wide);
  110.      
  111.      gotoxy(upCOL,upROW);
  112.      put_ca(UL,attr,1);
  113.      
  114.      gotoxy(lowCOL,upROW);
  115.      put_ca(UR,attr,1);
  116.      
  117.      
  118.      gotoxy(upCOL,lowROW);
  119.      put_ca(LL,attr,1);
  120.      
  121.      gotoxy(lowCOL,lowROW);
  122.      put_ca(LR,attr,1);
  123.      
  124.      for(x = upROW+1;x < lowROW;x++)   {
  125.           gotoxy(upCOL,x);
  126.           put_ca(SD,attr,1);
  127.           gotoxy(lowCOL,x);
  128.           put_ca(SD,attr,1);
  129.      }
  130. }
  131.  
  132.  
  133.  
  134. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  135. /*  ║ Function :  ccls();                                                  ║  */
  136. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  137. /*  ║ clears the screen and sets the attribute        (ex: ccls(7);)       ║  */
  138. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  139. /*  ║ Usage    : ccls(attribute);                                          ║  */
  140. /*  ║                                                                      ║  */
  141. /*  ║ Returns  : nothing                                                   ║  */
  142. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  143. void ccls(attr)
  144. int attr;
  145. {
  146.      inreg.h.ah = 6;
  147.      inreg.h.al = 0;
  148.      inreg.h.bh = attr;
  149.      inreg.h.ch = 0;
  150.      inreg.h.cl = 0;
  151.      inreg.h.dh = 24;
  152.      inreg.h.dl =79;
  153.      int86(0x10, &inreg, &outreg);
  154. }
  155.  
  156.  
  157. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  158. /*  ║ Function :  cls();                                                   ║  */
  159. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  160. /*  ║ clears the screen and homes the cursor                               ║  */
  161. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  162. /*  ║ Usage    : cls();                                                    ║  */
  163. /*  ║                                                                      ║  */
  164. /*  ║ Returns  : nothing                                                   ║  */
  165. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  166. void cls(void)
  167. {
  168.      int mode;
  169.      
  170.      mode = vmode();     /* read current video mode */
  171.      smode(mode);        /* set the same video mode */
  172. }
  173.  
  174.  
  175. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  176. /*  ║ Function :  cursor();                                                ║  */
  177. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  178. /*  ║ turns the cursor off                                                 ║  */
  179. /*  ║ also sets cursor to normal size [ _ ]  or full size [ █ ]            ║  */
  180. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  181. /*  ║ Usage    : cursor(type);                                             ║  */
  182. /*  ║                                                                      ║  */
  183. /*  ║            type    0 = cursor off                                    ║  */
  184. /*  ║                    1 = normal cursor                                 ║  */
  185. /*  ║                    2 = full size                                     ║  */
  186. /*  ║                                                                      ║  */
  187. /*  ║ Returns  : nothing                                                   ║  */
  188. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  189. void cursor(type)
  190. int type;
  191. {
  192.      unsigned int equip;
  193.  
  194.      inreg.h.ah = 1;
  195.  
  196.      equip=biosequip();
  197.     if((equip & 0x30)==0x30)  /* If monochrome card value will be 0x30 */
  198.       {
  199.       if (type == 0)
  200.          inreg.x.cx = 0x0F0F;
  201.       else if (type == 1)
  202.          inreg.x.cx = 0x0C0D;
  203.       else if (type == 2)
  204.          inreg.x.cx = 0x010D;
  205.       }
  206.    else                               /* color */
  207.       {
  208.       if (type == 0)
  209.          inreg.x.cx = 0x0F0F;
  210.       else if (type == 1)
  211.          inreg.x.cx = 0x0607;
  212.       else if (type == 2)
  213.          inreg.x.cx = 0x0107;
  214.       }
  215.  
  216.    int86(0x10, &inreg, &outreg);
  217. }
  218.  
  219.  
  220. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  221. /*  ║ Function :  gotoxy();           (x = col      y = row)               ║  */
  222. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  223. /*  ║ positions the cursor to x,y                                          ║  */
  224. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  225. /*  ║ Usage    : gotoxy(x,y);                                              ║  */
  226. /*  ║                                                                      ║  */
  227. /*  ║ Returns  : nothing                                                   ║  */
  228. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  229. void gotoxy(col,row)
  230. int  col,row;
  231. {
  232.      inreg.h.ah = 2;
  233.      inreg.h.dl = col;
  234.      inreg.h.dh = row;
  235.      inreg.h.bh = 0;
  236.      int86(0x10, &inreg, &outreg);
  237. }
  238.  
  239.  
  240. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  241. /*  ║ Function :  put_ca();                                                ║  */
  242. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  243. /*  ║  use bios to a print character and attribute to the screen  for      ║  */
  244. /*  ║  specified number of times (repeats)                                 ║  */
  245. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  246. /*  ║ Usage    : put_ca(char, attr, num);                                  ║  */
  247. /*  ║                                                                      ║  */
  248. /*  ║ Returns  : nothing                                                   ║  */
  249. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  250. void put_ca(chr,attr,num)
  251. char chr;
  252. int attr,num;
  253. {
  254.      inreg.h.ah = 9;
  255.      inreg.h.al = chr;
  256.      inreg.h.bh = 0;
  257.      inreg.h.bl = attr;
  258.      inreg.x.cx = num;
  259.      
  260.      int86(0x10,&inreg,&outreg);
  261. }
  262.  
  263. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  264. /*  ║ Function :  put_cai();                                               ║  */
  265. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  266. /*  ║  use bios to a print character and attribute to the screen and       ║  */
  267. /*  ║  increment the cursor                                                ║  */
  268. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  269. /*  ║ Usage    : put_cai(char, attr);                                      ║  */
  270. /*  ║                                                                      ║  */
  271. /*  ║ Returns  : nothing                                                   ║  */
  272. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  273. void put_cai(chr,attr)
  274. char chr;
  275. int attr;
  276. {
  277.      int x,y;
  278.      
  279.      inreg.h.ah = 9;
  280.      inreg.h.al = chr;
  281.      inreg.h.bh = 0;
  282.      inreg.h.bl = attr;
  283.      inreg.x.cx = 1;
  284.      int86(0x10,&inreg,&outreg);
  285.      
  286.      x = where_x();
  287.      y = where_y();
  288.      x++;
  289.      if(x > 79)   {
  290.           x = 0;
  291.           y++;
  292.      }
  293.      if(y > 24)  {
  294.           scroll(0,0,79,24,1,0);
  295.           y = 24;
  296.      }
  297.      gotoxy(x,y);
  298. }
  299.  
  300. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  301. /*  ║ Function :  put_str();                                               ║  */
  302. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  303. /*  ║  use bios to a print a string and attribute to the screen            ║  */
  304. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  305. /*  ║ Usage    : put_str(string,attr);                                     ║  */
  306. /*  ║                                                                      ║  */
  307. /*  ║ Returns  : nothing                                                   ║  */
  308. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  309. void put_str(str, attr)
  310. char *str;
  311. int attr;
  312. {
  313.      register int    i;
  314.      for(i=0;*str != '\0';++str,++i) 
  315.      put_cai(*str,attr);
  316. }
  317.  
  318.  
  319. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  320. /*  ║ Function :  scroll();                                                ║  */
  321. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  322. /*  ║ scroll window up/down                                                ║  */
  323. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  324. /*  ║ Usage    : scroll(x1,y1,x2,y2,num,dir);                              ║  */
  325. /*  ║                 x1  = left column                                    ║  */
  326. /*  ║                 y1  = upper row                                      ║  */
  327. /*  ║                 x2  = right column                                   ║  */
  328. /*  ║                 y2  = lower row                                      ║  */
  329. /*  ║                 num = lines to scroll                                ║  */
  330. /*  ║                 dir = direction of scroll (0=up   1=down)            ║  */
  331. /*  ║                                                                      ║  */
  332. /*  ║ Returns  : nothing                                                   ║  */
  333. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  334. int scroll(x1,y1,x2,y2,num,dir)
  335. int x1,y1,x2,y2,num,dir;
  336. {
  337.      
  338.      inreg.h.ah      = 6 + dir;
  339.      inreg.h.al      = num;
  340.      inreg.h.bh      = 7;
  341.      inreg.h.ch      = y1;
  342.      inreg.h.cl      = x1;
  343.      inreg.h.dh      = y2;
  344.      inreg.h.dl      = x2;
  345.      
  346.      int86(0x10,&inreg,&outreg);
  347. }
  348.  
  349.  
  350. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  351. /*  ║ Function :  smode();                                                 ║  */
  352. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  353. /*  ║ sets the video mode                                                  ║  */
  354. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  355. /*  ║ Usage    : smode(7);                                                 ║  */
  356. /*  ║                                                                      ║  */
  357. /*  ║ Returns  : nothing                                                   ║  */
  358. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  359. void smode(int mode)
  360. {
  361.      inreg.h.ah = 0;
  362.      inreg.h.al = mode;
  363.      int86(0x10, &inreg, &outreg);
  364. }
  365.  
  366.  
  367. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  368. /*  ║ Function :  vmode();                                                 ║  */
  369. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  370. /*  ║ returns the current video mode                                       ║  */
  371. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  372. /*  ║ Usage    : a = vmode();                                              ║  */
  373. /*  ║                                                                      ║  */
  374. /*  ║ Returns  : video mode to specified variable                          ║  */
  375. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  376. int vmode(void)
  377. {
  378.      inreg.h.ah = 15;
  379.      int86(0x10, &inreg, &outreg);
  380.      return outreg.h.al;
  381. }
  382.  
  383.  
  384. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  385. /*  ║ Function :  what_xy();                                               ║  */
  386. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  387. /*  ║ returns the character at x,y  to a specified variable  (x=col y=row) ║  */
  388. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  389. /*  ║ Usage    : a = what_xy(x,y);                                         ║  */
  390. /*  ║                                                                      ║  */
  391. /*  ║ Returns  : Character at x,y                                          ║  */
  392. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  393. char what_xy(x1,y1)
  394. int     x1,y1;
  395. {
  396.      gotoxy (x1,y1);
  397.      inreg.h.ah      = 8;
  398.      inreg.h.bh      = 0;
  399.      
  400.      int86(0x10,&inreg,&outreg);
  401.      
  402.      return(outreg.h.al);
  403. }
  404.  
  405.  
  406. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  407. /*  ║ Function :  where_x();                                               ║  */
  408. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  409. /*  ║ locates the column position of the cursor                            ║  */
  410. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  411. /*  ║ Usage    : x = where_x();                                            ║  */
  412. /*  ║                                                                      ║  */
  413. /*  ║ Returns  : the column position (x)                                   ║  */
  414. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  415. int where_x(void)
  416. {
  417.      unsigned int x;
  418.      inreg.h.ah = 3;
  419.      inreg.h.bh = 0;
  420.      int86(0x10, &inreg, &outreg);
  421.      x = outreg.h.dl;
  422.      
  423.      return x;
  424. }
  425.  
  426.  
  427. /*  ╔══════════════════════════════════════════════════════════════════════╗  */
  428. /*  ║ Function :  where_y();                                               ║  */
  429. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  430. /*  ║ locates the row position of the cursor                               ║  */
  431. /*  ╠══════════════════════════════════════════════════════════════════════╣  */
  432. /*  ║ Usage    : y = where_y();                                            ║  */
  433. /*  ║                                                                      ║  */
  434. /*  ║ Returns  : the row position (y)                                      ║  */
  435. /*  ╚══════════════════════════════════════════════════════════════════════╝  */
  436. int where_y(void)
  437. {
  438.      unsigned int y;
  439.      inreg.h.ah = 3;
  440.      inreg.h.bh = 0;
  441.      int86(0x10, &inreg, &outreg);
  442.      y = outreg.h.dh;
  443.      
  444.      return y;
  445. }
  446.  
  447.  
  448.